package com.zzptc.sky.baidudemo.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.activities.BaiBoxActivity;
import com.zzptc.sky.baidudemo.activities.FamilyGuardianActivity;
import com.zzptc.sky.baidudemo.activities.MainActivity;
import com.zzptc.sky.baidudemo.utils.MyApplication;
import com.zzptc.sky.baidudemo.utils.MyUntils;
import com.zzptc.sky.baidudemo.vo.BaiBoxInfo;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24 024 .
 */

public class BoxAdapter extends RecyclerView.Adapter<BoxAdapter.MyHolder> {
    private List<BaiBoxInfo> list;
    private View itemView;

    public BoxAdapter(List<BaiBoxInfo> list) {
        this.list = list;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.box_items,parent,false);
        MyHolder myHolder = new MyHolder(itemView);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        final BaiBoxInfo info = list.get(position);
        holder.rv_tv.setText(info.getName());
        holder.rv_iv.setImageDrawable(MyUntils.getBaiBoxIcon(info.getIcon()));

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (info.getName()){
                   case "家人守护":
                       MyApplication.getContext().startActivity(new Intent(MyApplication.getContext(), FamilyGuardianActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                       break;
                    case "回首页":
//                        MyApplication.getContext().startActivity(new Intent(MyApplication.getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                        BaiBoxActivity.getActivity().finish();
                        break;
               }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class MyHolder extends RecyclerView.ViewHolder{
        private TextView rv_tv;
        private ImageView rv_iv;

        public MyHolder(View itemView) {
            super(itemView);
            rv_tv = (TextView) itemView.findViewById(R.id.rv_tv);
            rv_iv = (ImageView) itemView.findViewById(R.id.rv_iv);
        }
    }

}
